<template>
  <div class="base_card" @click="_click">
    <div class="base_card_content">
      <p v-if="title" class="base_card_title">
        <span>{{ title }}</span>
        <van-icon v-if="arrow" class="into" name="arrow" @click="into" />
      </p>
      <div v-for="(item, index) in data" :key="index" class="base_card_row">
        <span class="base_card_key">{{ item.key }}</span>
        <span
          :class="item.danger ? 'base_card_value danger' : 'base_card_value'"
          >{{ item.value }}</span>
      </div>
    </div>
    <div class="base_card_bottom">
      <span v-if="leftText && rightText" class="mid_line" @click="leftClick">{{
        leftText
      }}</span>
      <span v-if="leftText && rightText" class="danger" @click="rightClick">{{
        rightText
      }}</span>
      <span
        v-if="bottomText"
        :class="danger ? 'danger' : ''"
        @click.stop="bottomClick"
        >{{ bottomText }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'baseCard',
  props: {
    // 传值类型 [{key:'', value: ''},...]
    data: {
      type: Array,
      default: () => []
    },
    title: {
      type: String,
      default: ''
    },
    // 展示右箭头
    arrow: {
      type: Boolean,
      default: false
    },
    leftText: {
      type: String,
      default: ''
    },
    rightText: {
      type: String,
      default: ''
    },
    bottomText: {
      type: String,
      default: ''
    },
    // 红色
    danger: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      isCollapse: true
    }
  },
  created() {},
  mounted() {},
  methods: {
    _click() {
      this.$emit('click')
    },
    leftClick() {
      this.$emit('leftClick')
    },
    rightClick() {
      this.$emit('rightClick')
    },
    bottomClick() {
      this.$emit('bottomClick')
    },
    into() {
      this.$emit('into')
    }
  }
}
</script>

<style lang="scss" scoped>
.base_card {
  width: 345px;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0px 2px 8px 0px rgba(178, 184, 189, 0.1);
  position: relative;
  &_content{
    padding: 15px 15px 0 15px;
  }

  &_row {
    margin-bottom: 10px;
    display: flex;

    // &:last-of-type {
    //   margin-bottom: 0;
    // }
  }

  &_title {
    font-family: PingFang SC Medium;
    font-size: 16px;
    font-weight: normal;
    line-height: 22px;
    letter-spacing: 0px;
    color: #171819;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .into {
      font-size: 12px;
      color: #b2b8bd;
    }

    .danger {
      font-family: PingFangSCMedium-Medium;
      font-size: 12px;
      /* 错误色/错误色 */
      color: #ea0000;
      display: inline-block;
      width: 86px;
      height: 18px;
      text-align: center;
      line-height: 18px;
      /* 错误色/错误色 */
      border: 0.5px solid #ea0000;
      border-radius: 2px;
    }
  }

  &_key {
    font-family: PingFang SC Regular;
    font-size: 14px;
    font-weight: normal;
    line-height: 24px;
    letter-spacing: 0px;
    color: #656c74;
    width: 84px;
    display: inline-block;
    margin-right: 15px;
  }

  &_value {
    font-family: PingFang SC Regular;
    font-size: 14px;
    font-weight: normal;
    line-height: 24px;
    letter-spacing: 0px;
    color: #171819;

    &.danger {
      color: #fe3737;
    }
  }

  &_bottom {
    text-align: center;
    border-width: 0.5px 0 0 0;
    border-style: solid;
    border-color: #ebebeb;
    width: 100%;
    height: 46px;
    line-height: 46px;
    text-align: center;
    background: #fff;
    display: flex;

    span {
      display: block;
      flex: 1;
      font-family: PingFang SC Regular;
      font-size: 14px;
      font-weight: normal;
      text-align: center;
      color: #2163e0;

      &.danger {
        color: #ff5454;
      }

      &.mid_line {
        border-width: 0 0.5px 0 0;
        border-style: solid;
        border-color: #ebebeb;
      }
    }
  }
}
</style>
